package com.example.demo.util

import org.reflections.Reflections
import org.reflections.util.ClasspathHelper
import org.reflections.util.ConfigurationBuilder
import org.reflections.util.FilterBuilder

/**
 * @author Xu Haidong
 * @date 2023/4/21 10:27
 */

fun getReflections(location: String?): Reflections {
  if (location.isNullOrBlank()) {
    throw RuntimeException("路径不能为空")
  }
  val configurationBuilder = ConfigurationBuilder()
  val filterBuilder = FilterBuilder()
  location.split(",").forEach {
    configurationBuilder.addUrls(ClasspathHelper.forPackage(it.trim()))
    filterBuilder.includePackage(it.trim())
  }
  configurationBuilder.filterInputsBy(filterBuilder)
  return Reflections(configurationBuilder)
}
